﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace EzyChoice
{
    [Serializable()]
    public class EzcPerson : TreeNode,  ISerializable
    {
        protected string guid;

        public bool IsSummary;

        public string ID
        {
            get
            {
                return guid;
            }
            
        }

        public EzcPerson()
        {
            this.guid = Guid.NewGuid().ToString();
            this.Checked = true;
        }

        public override string ToString()
        {
            return Name;
        }

        public EzcPerson(string name)
        {
            Name = name;
            Text = name;
            this.guid = Guid.NewGuid().ToString();
            this.Checked = true;
        }

        protected EzcPerson(SerializationInfo info, StreamingContext context)
        {
            this.Name = this.Text = (string)info.GetValue("name", typeof(string));
            this.guid = (string)info.GetValue("guid", typeof(string));
            this.Checked = (bool)info.GetValue("selected", typeof(bool));
            this.IsSummary = (bool)info.GetValue("summary", typeof(bool));
        }

        public virtual void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("name", this.Name);
            info.AddValue("guid", this.guid);
            info.AddValue("selected", this.Checked);
            info.AddValue("summary", this.IsSummary);
        }
    }
}
